package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.OrderDisClan;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 真系亲属表 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-08-02
 */
public interface OrderDisClanMapper extends BaseMapper<OrderDisClan> {

    /**
     * 获取直系亲属姓名
     *
     * @param studentId 学生id
     * @return
     */
    @Select("SELECT GROUP_CONCAT( clan_name SEPARATOR ', ' ) AS clan_names FROM ( SELECT getStudentNameForId ( t1.student_id ) AS clan_name  FROM order_dis_clan AS t1 INNER JOIN order_apply AS t2 ON t1.order_id = t2.id WHERE t2.student_id =#{studentId} AND t1.student_id <> 1 GROUP BY t1.student_id UNION ALL SELECT getStudentNameForId ( t2.student_id ) AS clan_name FROM order_dis_clan AS t1 INNER JOIN order_apply AS t2 ON t1.order_id = t2.id WHERE t1.student_id = #{studentId} AND t2.student_id <> 1 GROUP BY t2.student_id )AS combined_clans;")
    String getClanName(@Param("studentId") Long studentId);
}
